<?php
$fileName = $_GET['i'];
if (empty($fileName) || !preg_match('#^\w+\.jpg$#', $fileName)) {
	exit('error');
}
$time = time();
$expire = 365*24*3600;
$etag = str_replace('.', '', $fileName);
header("Cache-control: max-age=".$expire);
header("Expires: " . gmdate("D, d M Y H:i:s",$time+$expire) . "GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s",$time) . "GMT");
header('Content-Type: image/jpeg');
if(isset($_SERVER['HTTP_IF_NONE_MATCH']) && $etag == $_SERVER['HTTP_IF_NONE_MATCH']){
	header('Etag:' . $etag, true, 304);
	exit();
}else{
	header('Etag:' . $etag);
}
//header('Cache-Control: no-store, no-cache, must-revalidate');
echo file_get_contents("images/$fileName");